// Button.cpp
#include "Button.h"

namespace ANvDbg
{
    Button::Button() : m_is_press(false)
    {

    }

    void Button::Init(float pos_x, float pos_y, float image_width, float image_height)
    {
        m_pos_x = pos_x;
        m_pos_y = pos_y;
        m_image_width = image_width;
        m_image_height = image_height;

        m_image_sprite->Init(pos_x, pos_y, image_width, image_height);
    }

    void Button::Render()
    {
        glPushMatrix();

        if (m_is_press)
        {
            glTranslatef(2.f, -2.f, 0.f);
        }

        m_image_sprite->Render();

        glPopMatrix();
    }

    bool Button::HitTest(int pos_x, int pos_y)
    {
        if (pos_x > m_pos_x - m_image_width / 2.f
            && pos_x < m_pos_x + m_image_width / 2.f
            && pos_y > m_pos_y - m_image_height / 2.f
            && pos_y < m_pos_y + m_image_height / 2.f)
        {
            m_image_sprite->FadeIn(1.f);

            return true;
        }

        return false;
    }
}
